如果要得到系統資訊或 WMI 資訊,網路上的介紹有一部分會提到 WMIC 指令,WMIC 是甚麼呢? WMIC 是一個 Windows 的命令列和腳本接口,簡化了使用 WMI 和透過 WMI 管理系統的功能,可以提供大量有關本機和遠端電腦的資訊。如果不想深入了解 WMI,如 WMI 的樹狀結構、命名空間與資料庫等複雜內容,用 WMIC 工具得到的系統資訊也已經很豐富了。下面就來介紹如何使用 WMIC。
Windows 中可以使用
步驟
>wmic /?
WMIC is deprecated.
[global switches] <command>
The following global switches are available:
/NAMESPACE Path for the namespace the alias operate against.
/ROLE Path for the role containing the alias definitions.
/NODE Servers the alias will operate against.
/IMPLEVEL Client impersonation level.
/AUTHLEVEL Client authentication level.
/LOCALE Language id the client should use.
/PRIVILEGES Enable or disable all privileges.
/TRACE Outputs debugging information to stderr.
/RECORD Logs all input commands and output.
/INTERACTIVE Sets or resets the interactive mode.
/FAILFAST Sets or resets the FailFast mode.
/USER User to be used during the session.
/PASSWORD Password to be used for session login.
/OUTPUT Specifies the mode for output redirection.
/APPEND Specifies the mode for output redirection.
/AGGREGATE Sets or resets aggregate mode.
/AUTHORITY Specifies the <authority type> for the connection.
/?[:<BRIEF|FULL>] Usage information.
For more information on a specific global switch, type: switch-name /?
The following alias/es are available in the current role:
ALIAS - Access to the aliases available on the local system
BASEBOARD - Base board (also known as a motherboard or system board) management.
BIOS - Basic input/output services (BIOS) management.
BOOTCONFIG - Boot configuration management.
CDROM - CD-ROM management.
COMPUTERSYSTEM - Computer system management.
CPU - CPU management.
CSPRODUCT - Computer system product information from SMBIOS.
DATAFILE - DataFile Management.
DCOMAPP - DCOM Application management.
DESKTOP - User's Desktop management.
DESKTOPMONITOR - Desktop Monitor management.
DEVICEMEMORYADDRESS - Device memory addresses management.
DISKDRIVE - Physical disk drive management.
DISKQUOTA - Disk space usage for NTFS volumes.
DMACHANNEL - Direct memory access (DMA) channel management.
ENVIRONMENT - System environment settings management.
FSDIR - Filesystem directory entry management.
GROUP - Group account management.
IDECONTROLLER - IDE Controller management.
IRQ - Interrupt request line (IRQ) management.
JOB - Provides access to the jobs scheduled using the schedule service.
LOADORDER - Management of system services that define execution dependencies.
LOGICALDISK - Local storage device management.
LOGON - LOGON Sessions.
MEMCACHE - Cache memory management.
MEMORYCHIP - Memory chip information.
MEMPHYSICAL - Computer system's physical memory management.
NETCLIENT - Network Client management.
NETLOGIN - Network login information (of a particular user) management.
NETPROTOCOL - Protocols (and their network characteristics) management.
NETUSE - Active network connection management.
NIC - Network Interface Controller (NIC) management.
NICCONFIG - Network adapter management.
NTDOMAIN - NT Domain management.
NTEVENT - Entries in the NT Event Log.
NTEVENTLOG - NT eventlog file management.
ONBOARDDEVICE - Management of common adapter devices built into the motherboard (system board).
OS - Installed Operating System/s management.
PAGEFILE - Virtual memory file swapping management.
PAGEFILESET - Page file settings management.
PARTITION - Management of partitioned areas of a physical disk.
PORT - I/O port management.
PORTCONNECTOR - Physical connection ports management.
PRINTER - Printer device management.
PRINTERCONFIG - Printer device configuration management.
PRINTJOB - Print job management.
PROCESS - Process management.
PRODUCT - Installation package task management.
QFE - Quick Fix Engineering.
QUOTASETTING - Setting information for disk quotas on a volume.
RDACCOUNT - Remote Desktop connection permission management.
RDNIC - Remote Desktop connection management on a specific network adapter.
RDPERMISSIONS - Permissions to a specific Remote Desktop connection.
RDTOGGLE - Turning Remote Desktop listener on or off remotely.
RECOVEROS - Information that will be gathered from memory when the operating system fails.
REGISTRY - Computer system registry management.
SCSICONTROLLER - SCSI Controller management.
SERVER - Server information management.
SERVICE - Service application management.
SHADOWCOPY - Shadow copy management.
SHADOWSTORAGE - Shadow copy storage area management.
SHARE - Shared resource management.
SOFTWAREELEMENT - Management of the elements of a software product installed on a system.
SOFTWAREFEATURE - Management of software product subsets of SoftwareElement.
SOUNDDEV - Sound Device management.
STARTUP - Management of commands that run automatically when users log onto the computer system.
SYSACCOUNT - System account management.
SYSDRIVER - Management of the system driver for a base service.
SYSTEMENCLOSURE - Physical system enclosure management.
SYSTEMSLOT - Management of physical connection points including ports, slots and peripherals, and proprietary connections points.
TAPEDRIVE - Tape drive management.
TEMPERATURE - Data management of a temperature sensor (electronic thermometer).
TIMEZONE - Time zone data management.
UPS - Uninterruptible power supply (UPS) management.
USERACCOUNT - User account management.
VOLTAGE - Voltage sensor (electronic voltmeter) data management.
VOLUME - Local storage volume management.
VOLUMEQUOTASETTING - Associates the disk quota setting with a specific disk volume.
VOLUMEUSERQUOTA - Per user storage volume quota management.
WMISET - WMI service operational parameters management.
For more information on a specific alias, type: alias /?
CLASS - Escapes to full WMI schema.
PATH - Escapes to full WMI object paths.
CONTEXT - Displays the state of all the global switches.
QUIT/EXIT - Exits the program.
For more information on CLASS/PATH/CONTEXT, type: (CLASS | PATH | CONTEXT) /?
由 Result 我們可以知道的事情有,Microsoft 的 WMIC Tool 目前是棄用狀態,但還是可以在 Windows 使用。
我們可以得到 WMIC 的 Switches 和 Aliases 清單,Switches 用來設定預設的 WMIC 環境。Aliases (別名) 協助 WMIC 執行存取 WMI 基礎結構,是獲取某些特定任務(如處理器、磁碟或網路管理)相關的 classes、 properties, 和 method 的友善集合名稱,使輸出格式更加簡單明瞭。 可以使用的 Aliases 從 ALIAS 到 WMISET,使用 wmic Alias 指令可得到 Alias 對應的資訊,如 wmi CPU、 wmi BIOS 等。
以 CPU 這個 Alias 為例,一步步了解如何使用 WMIC。
> wmic CPU /?
CPU - CPU management.
HINT: BNF for Alias usage.
(<alias> [WMIObject] | <alias> [<path where>] | [<alias>] <path where>) [<verb clause>].
USAGE:
CPU ASSOC [<format specifier>]
CPU CREATE <assign list>
CPU DELETE
CPU GET [<property list>] [<get switches>]
CPU LIST [<list format>] [<list switches>]
我們可以知道 CPU 這個 Alias 有 ASSOC、 CREATE、 DELETE、 GET、 LIST 這些指令可用,要取得資料當然是使用 GET。
> wmic CPU GET /?
Property get operations.
USAGE:
GET [<property list>] [<get switches>]
NOTE: <property list> ::= <property name> | <property name>, <property list>
The following properties are available:
Property Type Operation
======== ==== =========
AddressWidth N/A N/A
Architecture N/A N/A
Availability N/A N/A
Caption N/A N/A
ConfigManagerErrorCode N/A N/A
ConfigManagerUserConfig N/A N/A
CpuStatus N/A N/A
CreationClassName N/A N/A
CurrentClockSpeed N/A N/A
CurrentVoltage N/A N/A
DataWidth N/A N/A
Description N/A N/A
DeviceID N/A N/A
ErrorCleared N/A N/A
ErrorDescription N/A N/A
ExtClock N/A N/A
Family N/A N/A
InstallDate N/A N/A
L2CacheSize N/A N/A
L2CacheSpeed N/A N/A
LastErrorCode N/A N/A
Level N/A N/A
LoadPercentage N/A N/A
Manufacturer N/A N/A
MaxClockSpeed N/A N/A
Name N/A N/A
OtherFamilyDescription N/A N/A
PNPDeviceID N/A N/A
PowerManagementCapabilities N/A N/A
PowerManagementSupported N/A N/A
ProcessorId N/A N/A
ProcessorType N/A N/A
Revision N/A N/A
Role N/A N/A
SocketDesignation N/A N/A
Status N/A N/A
StatusInfo N/A N/A
Stepping N/A N/A
SystemCreationClassName N/A N/A
SystemName N/A N/A
UniqueId N/A N/A
UpgradeMethod N/A N/A
Version N/A N/A
VoltageCaps N/A N/A
The following GET switches are available:
/VALUE - Return value.
/ALL(default) - Return the data and metadata for the attribute.
/TRANSLATE:<table name> - Translate output via values from <table name>.
/EVERY:<interval> [/REPEAT:<repeat count>] - Returns value every (X interval) seconds, If /REPEAT specified the command is executed <repeat count> times.
/FORMAT:<format specifier> - Keyword/XSL filename to process the XML results.
NOTE: Order of /TRANSLATE and /FORMAT switches influences the appearance of output.
Case1: If /TRANSLATE precedes /FORMAT, then translation of results will be followed by formatting.
Case2: If /TRANSLATE succeeds /FORMAT, then translation of the formatted results will be done.
由 Property 這欄的內容,我們知道了 Alias CPU 可以得到那些資訊,接著就使用指令來得到資訊吧。
>wmic CPU
AddressWidth Architecture AssetTag Availability Caption ...
64 9 To Be Filled By O.E.M. 3 Intel64 Family 6 ...
有些有資訊、有些沒有,所以我們知道雖然 WMI 有著一定的資訊架構,
但系統沒有提供給 WMI 就是沒有,甚至會不支援,使用上要注意。
>wmic CPU get Name
Name
13th Gen Intel(R) Core(TM) i7-13700K
>wmic CPU get CurrentClockSpeed,MaxClockSpeed,NumberOfCores,NumberOfEnabledCore,NumberOfLogicalProcessors
CurrentClockSpeed MaxClockSpeed NumberOfCores NumberOfEnabledCore NumberOfLogicalProcessors
3400 3400 16 16 2
> wmic ALIAS PROCESS LIST BRIEF
FriendlyName PWhere Target
Process WHERE ProcessId='#' Select * from Win32_Process
> wmic ALIAS CPU LIST BRIEF
FriendlyName PWhere Target
CPU Where DeviceID='#' Select * from WIN32_PROCESSOR
> wmic ALIAS CPU LIST
Description FriendlyName PWhere Target
CPU management. CPU Where DeviceID='#' Select * from WIN32_PROCESSOR
{} 6 MSFT_CliConnection MSFT_CliConnection 2 ms_409 ROOT\CIMV2
{} 3 MSFT_CliFormat MSFT_CliFormat 2 LIST FULL
{} 4 MSFT_CliProperty MSFT_CliProperty 2 AddressWidth AddressWidth
{} 4 MSFT_CliProperty MSFT_CliProperty 2 Architecture Architecture
{} 4 MSFT_CliProperty MSFT_CliProperty 2 Availability Availability
{} 4 MSFT_CliProperty MSFT_CliProperty 2 Caption Caption
{} 4 MSFT_CliProperty MSFT_CliProperty 2 ConfigManagerErrorCode ConfigManagerErrorCode
{} 4 MSFT_CliProperty MSFT_CliProperty 2 ConfigManagerUserConfig ConfigManagerUserConfig
{} 4 MSFT_CliProperty MSFT_CliProperty 2 CpuStatus CpuStatus
{} 4 MSFT_CliProperty MSFT_CliProperty 2 CreationClassName CreationClassName
{} 4 MSFT_CliProperty MSFT_CliProperty 2 CurrentClockSpeed CurrentClockSpeed
{} 4 MSFT_CliProperty MSFT_CliProperty 2 CurrentVoltage CurrentVoltage
{} 4 MSFT_CliProperty MSFT_CliProperty 2 DataWidth DataWidth
{} 4 MSFT_CliProperty MSFT_CliProperty 2 Description Description
{} 4 MSFT_CliProperty MSFT_CliProperty 2 DeviceID DeviceID
{} 4 MSFT_CliProperty MSFT_CliProperty 2 ErrorCleared ErrorCleared
{} 4 MSFT_CliProperty MSFT_CliProperty 2 ErrorDescription ErrorDescription
{} 4 MSFT_CliProperty MSFT_CliProperty 2 ExtClock ExtClock
{} 4 MSFT_CliProperty MSFT_CliProperty 2 Family Family
{} 4 MSFT_CliProperty MSFT_CliProperty 2 InstallDate InstallDate
{} 4 MSFT_CliProperty MSFT_CliProperty 2 L2CacheSize L2CacheSize
{} 4 MSFT_CliProperty MSFT_CliProperty 2 L2CacheSpeed L2CacheSpeed
{} 4 MSFT_CliProperty MSFT_CliProperty 2 LastErrorCode LastErrorCode
{} 4 MSFT_CliProperty MSFT_CliProperty 2 Level Level
{} 4 MSFT_CliProperty MSFT_CliProperty 2 LoadPercentage LoadPercentage
{} 4 MSFT_CliProperty MSFT_CliProperty 2 Manufacturer Manufacturer
{} 4 MSFT_CliProperty MSFT_CliProperty 2 MaxClockSpeed MaxClockSpeed
{} 4 MSFT_CliProperty MSFT_CliProperty 2 Name Name
{} 4 MSFT_CliProperty MSFT_CliProperty 2 OtherFamilyDescription OtherFamilyDescription
{} 4 MSFT_CliProperty MSFT_CliProperty 2 PNPDeviceID PNPDeviceID
{} 4 MSFT_CliProperty MSFT_CliProperty 2 PowerManagementCapabilities PowerManagementCapabilities
{} 4 MSFT_CliProperty MSFT_CliProperty 2 PowerManagementSupported PowerManagementSupported
{} 4 MSFT_CliProperty MSFT_CliProperty 2 ProcessorId ProcessorId
{} 4 MSFT_CliProperty MSFT_CliProperty 2 ProcessorType ProcessorType
{} 4 MSFT_CliProperty MSFT_CliProperty 2 Revision Revision
{} 4 MSFT_CliProperty MSFT_CliProperty 2 Role Role
{} 4 MSFT_CliProperty MSFT_CliProperty 2 SocketDesignation SocketDesignation
{} 4 MSFT_CliProperty MSFT_CliProperty 2 Status Status
{} 4 MSFT_CliProperty MSFT_CliProperty 2 StatusInfo StatusInfo
{} 4 MSFT_CliProperty MSFT_CliProperty 2 Stepping Stepping
{} 4 MSFT_CliProperty MSFT_CliProperty 2 SystemCreationClassName SystemCreationClassName
{} 4 MSFT_CliProperty MSFT_CliProperty 2 SystemName SystemName
{} 4 MSFT_CliProperty MSFT_CliProperty 2 UniqueId UniqueId
{} 4 MSFT_CliProperty MSFT_CliProperty 2 UpgradeMethod UpgradeMethod
{} 4 MSFT_CliProperty MSFT_CliProperty 2 Version Version
{} 4 MSFT_CliProperty MSFT_CliProperty 2 VoltageCaps VoltageCaps
{} 3 MSFT_CliFormat MSFT_CliFormat 2 TABLE BRIEF
{} 4 MSFT_CliProperty MSFT_CliProperty 2 Caption Caption
{} 4 MSFT_CliProperty MSFT_CliProperty 2 DeviceID DeviceID
{} 4 MSFT_CliProperty MSFT_CliProperty 2 Manufacturer Manufacturer
{} 4 MSFT_CliProperty MSFT_CliProperty 2 MaxClockSpeed MaxClockSpeed
{} 4 MSFT_CliProperty MSFT_CliProperty 2 Name Name
{} 4 MSFT_CliProperty MSFT_CliProperty 2 SocketDesignation SocketDesignation
{} 3 MSFT_CliFormat MSFT_CliFormat 2 TABLE STATUS
{} 4 MSFT_CliProperty MSFT_CliProperty 2 Availability Availability
{} 4 MSFT_CliProperty MSFT_CliProperty 2 CpuStatus CpuStatus
{} 4 MSFT_CliProperty MSFT_CliProperty 2 CurrentVoltage CurrentVoltage
{} 4 MSFT_CliProperty MSFT_CliProperty 2 DeviceID DeviceID
{} 4 MSFT_CliProperty MSFT_CliProperty 2 ErrorCleared ErrorCleared
{} 4 MSFT_CliProperty MSFT_CliProperty 2 ErrorDescription ErrorDescription
{} 4 MSFT_CliProperty MSFT_CliProperty 2 LastErrorCode LastErrorCode
{} 4 MSFT_CliProperty MSFT_CliProperty 2 LoadPercentage LoadPercentage
{} 4 MSFT_CliProperty MSFT_CliProperty 2 Status Status
{} 4 MSFT_CliProperty MSFT_CliProperty 2 StatusInfo StatusInfo
{} 3 MSFT_CliFormat MSFT_CliFormat 2 TABLE CONFIG
{} 4 MSFT_CliProperty MSFT_CliProperty 2 AddressWidth AddressWidth
{} 4 MSFT_CliProperty MSFT_CliProperty 2 DataWidth DataWidth
{} 4 MSFT_CliProperty MSFT_CliProperty 2 DeviceID DeviceID
{} 4 MSFT_CliProperty MSFT_CliProperty 2 ExtClock ExtClock
{} 4 MSFT_CliProperty MSFT_CliProperty 2 L2CacheSize L2CacheSize
{} 4 MSFT_CliProperty MSFT_CliProperty 2 L2CacheSpeed L2CacheSpeed
{} 4 MSFT_CliProperty MSFT_CliProperty 2 MaxClockSpeed MaxClockSpeed
{} 4 MSFT_CliProperty MSFT_CliProperty 2 PowerManagementSupported PowerManagementSupported
{} 4 MSFT_CliProperty MSFT_CliProperty 2 ProcessorType ProcessorType
{} 4 MSFT_CliProperty MSFT_CliProperty 2 Revision Revision
{} 4 MSFT_CliProperty MSFT_CliProperty 2 SocketDesignation SocketDesignation
{} 4 MSFT_CliProperty MSFT_CliProperty 2 Version Version
{} 4 MSFT_CliProperty MSFT_CliProperty 2 VoltageCaps VoltageCaps
{} 3 MSFT_CliFormat MSFT_CliFormat 2 TABLE INSTANCE
{} 4 MSFT_CliProperty MSFT_CliProperty 2 DeviceID DeviceID
> wmic ALIAS CPU LIST FULL
Description=CPU management.
FriendlyName=CPU
PWhere=Where DeviceID='#'
Target=Select * from WIN32_PROCESSOR
__PATH=
__NAMESPACE=
__SERVER=
__DERIVATION={}
__PROPERTY_COUNT=6
__RELPATH=
__DYNASTY=MSFT_CliConnection
__SUPERCLASS=
__CLASS=MSFT_CliConnection
__GENUS=2
Authority=
Locale=ms_409
NameSpace=ROOT\CIMV2
Password=
Server=.
User=
__PATH=
__NAMESPACE=
__SERVER=
__DERIVATION={}
__PROPERTY_COUNT=3
__RELPATH=
__DYNASTY=MSFT_CliFormat
__SUPERCLASS=
__CLASS=MSFT_CliFormat
__GENUS=2
Format=LIST
Name=FULL
__PATH=
__NAMESPACE=
__SERVER=
__DERIVATION={}
__PROPERTY_COUNT=4
__RELPATH=
__DYNASTY=MSFT_CliProperty
__SUPERCLASS=
__CLASS=MSFT_CliProperty
__GENUS=2
Derivation=AddressWidth
Description=
Name=AddressWidth
... ...
__PATH=
__NAMESPACE=
__SERVER=
__DERIVATION={}
__PROPERTY_COUNT=4
__RELPATH=
__DYNASTY=MSFT_CliProperty
__SUPERCLASS=
__CLASS=MSFT_CliProperty
__GENUS=2
Derivation=CurrentClockSpeed
Description=
Name=CurrentClockSpeed
>WMIC CPU ASSOC